<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>代码生成基本信息</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="${ctx}/layui/css/layui.css" media="all"/>
    <link rel="stylesheet" href="${ctx}/systemStatic/style/admin.css">
    <link rel="stylesheet" href="${ctx}/iconfont/iconfont.css"/>
    <link rel="stylesheet" href="${ctx}/css/public.css">
    <link rel="stylesheet" href="${ctx}/systemStatic/style/systemStyle.css">
    <script type="text/javascript">
        var __ctx = "${ctx}";
    </script>
</head>
<body>


<script type="text/html" template>

    <form class="layui-form" method="post" action="{{serverPath.systemPath + layui.setter.sysLinkPath}}codeGen/genCodes" style="margin: auto 30px;" lay-filter="dataForm">

            <input type="txt" name="tableName" class="tableName" style="display: none;"/>
            <div class="layui-form-item">
                <label class="ccpui-generator-form-label">基本路径<span style="color:red">*</span></label>
                <div class="ccpui-generator-input-block">
                    <input type="text" name="basePackage" id="basePackage" placeholder="参照格式:com.ccp.dev" lay-verify="required"
                           autocomplete="off" class="layui-input" maxlength="50" value="com.ccp.dev">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="ccpui-generator-form-label">模块名<span style="color:red">*</span></label>
                <div class="ccpui-generator-input-block">
                    <input type="text" name="moduleName" id="moduleName" placeholder="参考模块名：user" lay-verify="required"
                           autocomplete="off" class="layui-input" maxlength="50">
                </div>
            </div>
            <div class="layui-form-item " id="classNameDiv">
                <label class="ccpui-generator-form-label">自定义类名</label>
                <div class="ccpui-generator-input-block">
                    <input type="text" name="classForClassName" id="classForClassName" placeholder="非必填项，不填写默认按照驼峰规范命名"
                           autocomplete="off" class="layui-input" maxlength="50">
                </div>
            </div>

            <div class="layui-form-item">
                <label class="ccpui-generator-form-label">作者<span style="color:red">*</span></label>
                <div class="ccpui-generator-input-block">
                    <input type="text" name="author" id="author" placeholder="请输入作者" lay-verify="required"
                           autocomplete="off" class="layui-input" maxlength="50">
                </div>
            </div>

            <div class="layui-form-item " id="primaryKeyDiv">
                <label class="ccpui-generator-form-label">主键</label>
                <div class="ccpui-generator-input-block" id="primarySelect">

                </div>
            </div>

            <div class="layui-form-item">
                <label class="ccpui-generator-form-label">显示完整页面</label>
                <div class="ccpui-generator-input-block">
                    <input name="isShowFull" type="radio" value="true" title="是"/>
                    <input name="isShowFull" type="radio" value="false" checked title="否"/>
                </div>
            </div>

            <div class="layui-form-item">
                <label class="ccpui-generator-form-label">打开方式</label>
                <div class="ccpui-generator-input-block">
                    <input name="selectOpenMode" lay-filter="selectOpenMode" type="radio" value="true" checked title="弹出窗口"/>
                    <input name="selectOpenMode" lay-filter="selectOpenMode" type="radio" value="false" title="跳转页面"/>
                </div>
            </div>

            <div class="layui-form-item primaryKeyDiv">
                <label class="ccpui-generator-form-label">流程选择</label>
                <div class="ccpui-generator-input-block">
                    <input type="text" name="flow" id="flow" placeholder="请输入需要绑定的流程Key" autocomplete="off" class="layui-input" maxlength="50">
                </div>
            </div>

            <!--<div class="layui-form-item" style="display: none;" id="selectColumnDiv">
                <label class="ccpui-generator-form-label">选择模板</label>
                <div class="layui-input-block" style="margin-left: 5px;float: left;width: 78%;">
                    <select name="selectColumn" lay-filter="selectColumn" lay-verify="required" id="selectColumn">
                        <option value="twoColumn">两列模板</option>
                        <option value="threeColumn">三列模板</option>
                    </select>
                </div>
            </div>-->

        <div class="layui-form-item" style="position: fixed;bottom: 15px;left: 0;margin-bottom: 0;width: 100%;">
            <div style="text-align: center;">
                <button type="submit" class="layui-btn btn-n" lay-submit>立即生成</button>
                <button type="reset" id="closeWindow" style="margin-left: 10px;" class="layui-btn btn-n layui-btn-danger btn-save">取消</button>
            </div>
        </div>
    </form>
</script>
<script src="${ctx}/public/component.js" type="text/javascript"></script>
<script src="${ctx}/layui/layui.js"></script>
<script>
    //Demo
    layui.config({
        base: serverPath.systemPath + staticPath.systemPath //静态资源所在路径
    }).extend({
        index: 'index' //主入口模块
    }).use(['index','form', 'layer','setter'], function () {
        var form = layui.form;
        var layer = layui.layer;
        var setter = layui.setter;
        var $ = layui.jquery;

        //关闭当前页面
        $("#closeWindow").click(function () {
            parent.layer.close(parent.layer.getFrameIndex(window.name));
        });

        var isBatch = '${isBatch}';
        if (isBatch === 'true') {
            $("#classNameDiv").attr("style","display:none;");
            $("#primaryKeyDiv").attr("style","display:none;");
            $("#primaryKeyColumn").removeAttr("lay-verify");
        }

        var classForClassName = '${classForClassName}';
        if(isBatch != 'true'){
            $("#classForClassName").val(classForClassName);
        }

        var tableName = '${tableName}';
        if (tableName != null) {
            $(".tableName").val(tableName);
            var data = {};
            data.tableName = tableName;
        }

        //查询所有列信息并放入下拉中
        var url = serverPath.systemPath + setter.sysLinkPath + 'codeGen/queryColumnKey?tableName=' + tableName;
        $.ajax({
            url: url,
            type: "GET",
            contentType: 'application/json',
            dataType: 'json',
            success : function(datas) {
                var data = datas.data;
                //加载数据
                var html = '<select id="primaryKeyColumn" name="primaryKeyColumn" lay-verify="required" lay-filter="primaryKeyColumn">';
                for (var i = 0; i < data.length; i++) {
                    if("PRIMARY" === data[i].columnkey){
                        html += '<option selected value="' + data[i].columnName+ '">' + data[i].columnName + '</option>';
                    }else{
                        html += '<option value="' + data[i].columnName+ '">' + data[i].columnName + '</option>';
                    }
                }
                html += '</select>';
                $("#primarySelect").append(html);
                form.render('select');
            }
        });


        $("form").submit(function () {
            setTimeout(function () {
                var index = parent.layer.getFrameIndex(window.name);
//                window.parent.layer.close(index);
                window.parent.layer.msg('执行成功,正在生成代码请稍后…', {icon: 1});
            },300)
        });
    });
</script>
</body>
</html>